home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 01 / monoscrn.asm < prev    next >
Assembly Source File  |  1990-10-27  |  10KB  |  211 lines

  1. ;*******************************************************************************
  2. ;|                                                                             |
  3. ;|      Module:         Monochrome Screen access from Windows 3.0              |
  4. ;|                                                                             |
  5. ;|      Description:    This module demonstrates how to access memory mapped   |
  6. ;|                      devices within the Windows environment.                |
  7. ;|                                                                             |
  8. ;|      Author:         Chris Schwartz  (c) 10/25/90                           |
  9. ;|                                                                             |
  10. ;*******************************************************************************
  11.  
  12.                 .MODEL SMALL  
  13.  
  14.                 PUBLIC  DllInit                 ;dll entry point
  15.                 PUBLIC  WEP                     ;dll exit point
  16.  
  17.                 PUBLIC  VioInit
  18.                 PUBLIC  VioWrtStrAttr
  19.                 PUBLIC  DpmActiveMode
  20.                 PUBLIC  DpmSelectorFromSegment
  21.  
  22.                 .DATA
  23.  
  24. bogusData       dw      8 DUP(0)        ;just to keep windows from wigging out
  25. wVideoSeg       dw      0
  26.  
  27.                 .CODE
  28. ;*******************************************************************************
  29. ;|                                                                             |
  30. ;|      FAR PASCAL Calling Convention                                          |
  31. ;|                                                                             |
  32. ;|      BOOL DllInit(VOID); - Dll entry point, called by windows during loading|
  33. ;|                                                                             |
  34. ;|      Entry Values:   DS = Library Data Segment       ES = Command Line Sel  |
  35. ;|                      DI = Module Handle              SI = Command Line Off  |
  36. ;|                      CX = Local Heap Size                                   |
  37. ;|                                                                             |
  38. ;|      Return Values:  AX  = 0 Failed, don't load                             |
  39. ;|                      AX != 0 Success, load this puppy.                      |
  40. ;|                                                                             |
  41. ;*******************************************************************************
  42. ;------------------------------------------------------------------------------- 
  43. DllInit         PROC    FAR
  44.                 mov     ax, 1           ;load this puppy
  45.                 ret
  46. DllInit         ENDP
  47.  
  48. ;*******************************************************************************
  49. ;|                                                                             |
  50. ;|      FAR PASCAL Calling Convention                                          |
  51. ;|                                                                             |
  52. ;|      BOOL WEP(WORD wExitMode); - Dll exit point                             |
  53. ;|                                                                             |
  54. ;|      Return Values:  AX  = 0 Failed Cleanup                                 |
  55. ;|                      AX != 0 Success                                        |
  56. ;|                                                                             |
  57. ;*******************************************************************************
  58. ;------------------------------------------------------------------------------- 
  59. WEP             PROC    FAR
  60.                 mov     ax, 1           ;goodbye
  61.                 ret     2
  62. WEP             ENDP
  63.  
  64. ;*******************************************************************************
  65. ;|                                                                             |
  66. ;|      FAR PASCAL Calling Convention                                          |
  67. ;|                                                                             |
  68. ;|      BOOL DpmActiveMode(VOID);                                              |
  69. ;|                                                                             |
  70. ;|      Return Values:  AX  = 0 Protected Mode under DPMI                      |
  71. ;|                      AX != 0 Real mode, or not under DPMI                   |
  72. ;|                                                                             |
  73. ;*******************************************************************************
  74. ;------------------------------------------------------------------------------- 
  75. DpmActiveMode   PROC    FAR
  76.                 mov     ax, 1686h       ;DPMI Mode Detection Op Code
  77.                 int     2Fh             ;only changes the AX register
  78.                 ret
  79. DpmActiveMode   ENDP
  80.  
  81. ;*******************************************************************************
  82. ;|                                                                             |
  83. ;|      FAR PASCAL Calling Convention                                          |
  84. ;|                                                                             |
  85. ;|      WORD DpmSelectorFromSegment(WORD);                                     |
  86. ;|                                                                             |
  87. ;|      Return Value:  AX = 0 Then function failed, else we have a selector.   |
  88. ;|                                                                             |
  89. ;*******************************************************************************
  90. ;-------------- Formal Parameters ---------------------------------------------- 
  91. wRealSegment    equ     [bp+06]
  92. ;------------------------------------------------------------------------------- 
  93. DpmSelectorFromSegment  PROC    FAR
  94.                 push    bp
  95.                 mov     bp, sp
  96.  
  97.                 mov     ax, 02h
  98.                 mov     bx, wRealSegment
  99.                 int     31h
  100.                 jnc     DpmSFSExit              ;return protected mode selector
  101.  
  102.                 xor     ax, ax                  ;return error code
  103. DpmSFSExit:
  104.                 pop     bp
  105.                 ret     2
  106. DpmSelectorFromSegment  ENDP
  107.  
  108. ;*******************************************************************************
  109. ;|                                                                             |
  110. ;|      FAR PASCAL Calling Convention                                          |
  111. ;|                                                                             |
  112. ;|      VOID VioInit(VOID);                                                    |
  113. ;|                                                                             |
  114. ;*******************************************************************************
  115. ;------------------------------------------------------------------------------- 
  116. VioInit         PROC    FAR
  117.                 push    ds
  118.                 mov     ax, DGROUP
  119.                 mov     ds, ax                  ;fixup the dll's data segment
  120.  
  121.                 call    DpmActiveMode
  122.                 or      ax, ax
  123.                 je      VioInitProtMode
  124.  
  125.                 mov     wVideoSeg, 0B000h
  126.                 ret
  127. VioInitProtMode:
  128.                 mov     ax, 0B000h              ;monochrome segment value
  129.                 push    ax
  130.                 call    DpmSelectorFromSegment
  131.                 or      ax, ax
  132.                 je      VioInitExit
  133.  
  134.                 mov     wVideoSeg, ax
  135. VioInitExit:
  136.                 pop     ds
  137.                 ret
  138. VioInit         ENDP
  139.  
  140. ;*******************************************************************************
  141. ;|                                                                             |
  142. ;*******************************************************************************
  143. ScreenOffset    PROC    NEAR
  144.                 mov     bx, ax
  145.                 mov     cx, 6
  146.                 shl     ax, cl
  147.                 sub     cx, 2
  148.                 shl     bx, cl
  149.                 add     ax, bx
  150.                 add     ax, dx
  151.                 shl     ax, 1
  152.                 mov     dx, wVideoSeg
  153.                 ret
  154. ScreenOffset    ENDP
  155.  
  156. ;*******************************************************************************
  157. ;|                                                                             |
  158. ;|      FAR PASCAL Calling Convention                                          |
  159. ;|                                                                             |
  160. ;|      VioWrtStrAttr(lpData, wLen, wRow, wCol, lpAttr)                        |
  161. ;|                                                                             |
  162. ;*******************************************************************************
  163. ;-------------- Formal Parameters ---------------------------------------------- 
  164. lpData          equ     [bp+16]
  165. wLen            equ     [bp+14]
  166. wRow            equ     [bp+12]
  167. wCol            equ     [bp+10]
  168. lpAttr          equ     [bp+06]
  169. ;------------------------------------------------------------------------------- 
  170. VioWrtStrAttr   PROC    FAR
  171.                 push    bp
  172.                 mov     bp, sp
  173.                 push    ds
  174.                 mov     ax, DGROUP
  175.                 mov     ds, ax                  ;fixup dll's data segment
  176.                 push    es
  177.                 push    di
  178.                 push    si
  179.  
  180.                 mov     ax, wRow
  181.                 mov     dx, wCol
  182.  
  183.                 call    ScreenOffset            ;returns proper video address
  184.                 or      dx, dx
  185.                 je      VioWrtStrAttrExit
  186.  
  187.                 mov     es, dx
  188.                 mov     di, ax
  189.                 mov     cx, wLen
  190.  
  191.                 lds     si, lpAttr
  192.                 lodsb
  193.                 mov     ah, al
  194.                 lds     si, lpData
  195.  
  196. VioWrtStrAttrLoop:
  197.  
  198.                 lodsb
  199.                 stosw
  200.                 loop    VioWrtStrAttrLoop   ;cook those puppies
  201.  
  202. VioWrtStrAttrExit:
  203.                 pop     si
  204.                 pop     di
  205.                 pop     es
  206.                 pop     ds
  207.                 pop     bp
  208.                 ret     14
  209. VioWrtStrAttr   ENDP
  210.                 END     DllInit
  211.